//
//  SearchContentCollectionViewCellFirst.m
//  XYFMApp
//
//  Created by 岁变 on 16/9/10.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "SearchContentCollectionViewCellFirst.h"
#import "XYMacro.h"

@interface SearchContentCollectionViewCellFirst () <UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation SearchContentCollectionViewCellFirst

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        _buttonOne = [UIButton buttonWithType:UIButtonTypeCustom];
        _buttonOne.backgroundColor = SLECTEDCOLOR;
        [_buttonOne setTitle:@"最近更新" forState:UIControlStateNormal];
        [_buttonOne setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_buttonOne addTarget:self action:@selector(clickButtonOne:) forControlEvents:UIControlEventTouchUpInside];
        _buttonOne.frame = CGRectMake(0, 0, SCREEN_WIDTH / 2, 40);
        [self.contentView addSubview:_buttonOne];
        
        _buttonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
        _buttonTwo.backgroundColor = NOTSLECTEDCOLOR;
        [_buttonTwo setTitle:@"最多播放" forState:UIControlStateNormal];
        [_buttonTwo setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_buttonTwo addTarget:self action:@selector(clickButtonTwo:) forControlEvents:UIControlEventTouchUpInside];
        _buttonTwo.frame = CGRectMake(SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2, 40);
        [self.contentView addSubview:_buttonTwo];
        
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 0;
        layout.itemSize = CGSizeMake(SCREEN_WIDTH, self.contentView.frame.size.height - 40);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, self.contentView.frame.size.height - 40) collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.bounces = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.scrollEnabled = NO;
        [_collectionView registerClass:[SearchContentCollectionViewCellFourth class] forCellWithReuseIdentifier:@"SearchContentCollectionViewCellFourth"];
        [self.contentView addSubview:_collectionView];
        
    }
    return self;
}


- (void)clickButtonOne:(UIButton *)button {
    
    _buttonOne.backgroundColor = SLECTEDCOLOR;
    _collectionView.contentOffset = CGPointMake(0, 0);
    _buttonTwo.backgroundColor = NOTSLECTEDCOLOR;
    
}


- (void)clickButtonTwo:(UIButton *)button {
    
    _buttonTwo.backgroundColor = SLECTEDCOLOR;
    _collectionView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
    _buttonOne.backgroundColor = NOTSLECTEDCOLOR;
    
}




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    SearchContentCollectionViewCellFourth *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SearchContentCollectionViewCellFourth" forIndexPath:indexPath];
    cell.contentView.backgroundColor = SCOLOR;
    if (indexPath.item == 0) {
        cell.model = _firstModel;
    } else {
        cell.model = _secondModel;
    }
    cell.keyword = _keyword;
    return cell;
    
}


- (void)setFirstModel:(SearchModelFirst *)firstModel {
    
    _firstModel = [[SearchModelFirst alloc] init];
    _firstModel = firstModel;
    [_collectionView reloadData];

}

- (void)setSecondModel:(SearchModelFirst *)secondModel {
    
    _secondModel = [[SearchModelFirst alloc] init];
    _secondModel = secondModel;
    [_collectionView reloadData];

}



@end
